package com.iflyun.redis.test;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;

public class Redis {
	private Redis() {

	}

	public static void main(String[] args) {

		final Logger logger = LoggerFactory.getLogger(Redis.class);
		// 连接本地的 Redis 服务
		@SuppressWarnings("resource")
		Jedis jedis = new Jedis("localhost");
		logger.info("Connection to server sucessfully");
		// 查看服务是否运行
		logger.info("Server is running: " + jedis.ping());

		// 清空缓存
		/* jedis.flushAll(); */

		// 存放hash对象
		/*
		 * jedis.hset("hash001", "key", "key001"); jedis.hset("hash001",
		 * "value", "value001");
		 */

		//scan搜索redis
		ScanParams scan = new ScanParams();
		scan.count(10);
		scan.match("0016:1:*");
		ScanResult<String> s = jedis.scan("0", scan);
		List<String> list = s.getResult();
		while (!"0".equals(s.getStringCursor())) {
			s = jedis.scan(s.getStringCursor(), scan);
			list.addAll(s.getResult());
		}
		for (String string : list) {
			logger.info(jedis.hget(string, "RealName"));
		}

		

	}

}
